// 引入express框架
const express = require('express');
const path = require('path');
// 创建网站服务器
const app = express();

// 实现静态资源访问功能
// static方法接收一个参数: 静态资源所在目录 用绝对路径
// 第一个参数可以指定虚拟路径
console.log(__dirname);
app.use('/static', express.static(path.join(__dirname, 'public')));

let list = `
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户列表</title>
    <link rel="stylesheet" href="http://localhost:3000/static/bootstrap.min.css">
    <style>
        body {
            background-color: #999;
        }
        .btn{
            diaplay: block;
            margin: 50px 0;
            margin-left: 100px;
        }
    </style>

</head>

<body>
    <div class="container">
        <h6>
            <a href="javascript:void(0)" class="btn btn-primary" id="openDialog">添加用户</a>
        </h6>
        <dialog id="myDialog">
            <h2>这是一个模态对话框</h2>
            <p>这里可以放一些重要信息</p>
            <button id="closeDialog">关闭</button>
        </dialog>
        <table class="table table-striped table-bordered">
            <tr>
                <td>用户名</td>
                <td>年龄</td>
                <td>爱好</td>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
            <tr>
                <td>用户名</td>
                <td>年龄</td>
                <td>爱好</td>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
            <tr>
                <td>用户名</td>
                <td>年龄</td>
                <td>爱好</td>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
            <tr>
                <td>用户名</td>
                <td>年龄</td>
                <td>爱好</td>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
            <tr>
                <td>用户名</td>
                <td>年龄</td>
                <td>爱好</td>
                <td>邮箱</td>
                <td>操作</td>
            </tr>
        </table>
    </div>
    <script>
        const openDialog = document.getElementById('openDialog')
        const dialog = document.getElementById('myDialog')
        const closeDialog = document.getElementById('closeDialog')

        openDialog.addEventListener('click', () => {
            dialog.showModal()
        })

        closeDialog.addEventListener('click', () => {
            dialog.close()
        })
    </script>
</body>

</html>
`
app.get('/list', (req, res) => {
    res.send(list)
})
app.listen(3000)
console.log('server started ...');